﻿/**
* @description  Class to handle display of loaded SWFs.
*/
package com.foed.media.displays {

	import flash.display.Sprite;

	import com.foed.media.controllers.MediaController;
	import com.foed.events.MediaEvent;

	public class SWFDisplay extends MediaDisplay {
	
		/**
		* @description  Once the MediaController creates a Loader instance, this display will attach it
		*				so it will be included in the DisplayList.
		*
		* @param  pEvent  Event fired by MediaController.
		*/	
		private function attachSWFLoader(pEvent:MediaEvent):void {
			createMediaClip();
			Sprite(_mediaClip).addChild(Sprite(getController().media));
		}

		/**
		* @description	Creates whatever object is necessary to load media (must be overridden by concrete classes).
		*/	
		override protected function createMediaClip():void {
			super.createMediaClip();
			_mediaClip = addChild(new Sprite());
		}
	
		/**
		* @description	Sets the MediaController whose media will be displayed.
		*
		* @param  pController  The MediaController with media to display.
		*/	
		override public function setController(pController:MediaController):void {
			super.setController(pController);
			getController().addEventListener(MediaEvent.LOAD, attachSWFLoader, false, 0, true);
			getController().addEventListener(MediaEvent.METADATA, setMetadata, false, 0, true);
		}

	}
	
}